<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* 滚动定义的参考点是最近的有滚动条的元素
      生效:定义的位置属性 比如 top0的时候被黏住
      失效:包含块底边跟定位的盒子底边重合的时候
      */
      * {
        margin: 0;
        padding: 0;
      }
      body {
        height: 6000px;
      }
      .header {
        background-color: #c08d25;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100px;
      }
      .list {
        background-color: #808080;
      }
      .list div:first-child {
        background-color: #96bbd7;
        font-size: 40px;
        position: sticky;
        /* 这里指离顶部20px就黏住 */
        top: 2px;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="header">头部区域</div>
      <div class="content">
        <div class="list">
          <div>A</div>
          <div>A1</div>
          <div>A2</div>
          <div>A3</div>
          <div>A4</div>
          <div>A5</div>
          <div>A6</div>
          <div>A7</div>
        </div>
      </div>
    </div>
    <script>
      let content = document.querySelector(".content");
      let list = "";
      for (let index = 0; index < 6; index++) {
        list += content.innerHTML;
      }
      content.innerHTML = list;
    </script>
  </body>
</html>
